package program.domain;


/**
 * @program: OSAlgorithms
 * @description: 进程控制块
 * @author: W
 * @create: 2021-10-20 13:31
 **/
public class PCB implements Comparable<PCB>{
    /**
     * 进程所执行程序的文件名
     */
    private String cmdName;

    /**
     * 进程ID
     */
    private String pid;

    /**
     * 到达时间
     */
    private Integer arriveTime;

    /**
     * 进程优先数
     */
    private Integer priority;

    /**
     * 进程时间轮转时间片
     */
    private Integer round;

    /**
     * 进程占用CPU时间
     */
    private Integer cpuTime;

    /**
     * 进程到完成还需要的时间(ms)
     */
    private Integer needTime;

    /**
     * 计数器
     */
    private Integer count = 0;

    /**
     * 进程的状态
     */
    private String state;

    /**
     * 占用内存空间大小
     */
    private int memorySize;

    /**
     * 需要访问的磁道号
     */
    private int track;

    /**
     * 磁盘读写时间
     */
    private int rwTime;

    /**
     * 下一个PCB
     */
    private PCB next;

    public PCB(){}

    public PCB(String cmdName, int memorySize) {
        this.cmdName = cmdName;
        this.memorySize = memorySize;
    }

    public PCB(String cmdName, Integer cpuTime, int memorySize) {
        this.cmdName = cmdName;
        this.cpuTime = cpuTime;
        this.memorySize = memorySize;
        this.needTime = cpuTime;
    }

    public PCB(String pid, Integer arriveTime, int track, int rwTime) {
        this.pid = pid;
        this.arriveTime = arriveTime;
        this.track = track;
        this.rwTime = rwTime;
    }

    public PCB(String pid, Integer arriveTime, Integer cpuTime, String state) {
        this.pid = pid;
        this.arriveTime = arriveTime;
        this.cpuTime = cpuTime;
        this.state = state;
    }

    public PCB(String cmdName, String pid, Integer arriveTime, Integer priority, Integer round, Integer cpuTime, Integer needTime, Integer count, String state, PCB next) {
        this.cmdName = cmdName;
        this.pid = pid;
        this.arriveTime = arriveTime;
        this.priority = priority;
        this.round = round;
        this.cpuTime = cpuTime;
        this.needTime = needTime;
        this.count = count;
        this.state = state;
        this.next = next;
    }

    public String getCmdName() {
        return cmdName;
    }

    public void setCmdName(String cmdName) {
        this.cmdName = cmdName;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public Integer getArriveTime() {
        return arriveTime;
    }

    public void setArriveTime(Integer arriveTime) {
        this.arriveTime = arriveTime;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Integer getRound() {
        return round;
    }

    public void setRound(Integer round) {
        this.round = round;
    }

    public Integer getCpuTime() {
        return cpuTime;
    }

    public void setCpuTime(Integer cpuTime) {
        this.cpuTime = cpuTime;
    }

    public Integer getNeedTime() {
        return needTime;
    }

    public void setNeedTime(Integer needTime) {
        this.needTime = needTime;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public int getTrack() {
        return track;
    }

    public void setTrack(int track) {
        this.track = track;
    }

    public int getRwTime() {
        return rwTime;
    }

    public void setRwTime(int rwTime) {
        this.rwTime = rwTime;
    }

    public PCB getNext() {
        return next;
    }

    public void setNext(PCB next) {
        this.next = next;
    }

    public int getMemorySize() {
        return memorySize;
    }

    public void setMemorySize(int memorySize) {
        this.memorySize = memorySize;
    }

    @Override
    public String toString() {
        return "PCB{" + "cmdName='" + cmdName + '\'' + ", pid=" + pid + ", arriveTime=" + arriveTime + ", priority=" + priority + ", round=" + round + ", cpuTime=" + cpuTime + ", needTime=" + needTime + ", count=" + count + ", state='" + state + '\'' + ", next=" + next + '}';
    }

    @Override
    public int compareTo(PCB o) {
        return this.getArriveTime().compareTo(o.getArriveTime());
    }

}
